<%--
  Created by IntelliJ IDEA.
  User: 匹诺曹
  Date: 2023/12/15
  Time: 17:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<style>
    .footer {
        display: flex;
        justify-content: center;
        align-items: center;
    }
</style>
<body>
<div class="skin-default" id="wrapper">
    <%@ include file="/static/pages/head/header.jsp" %>
    <%--中间内容--%>
    <div class="page-wrapper">
        <section class="page-body">
            <div class="row widget">
                <section class="col-md-12">
                    <div class="box table">
                        <div class="box-header">
                            <h3 class="box-title">员工信息展示</h3>
                        </div>
                        <div class="box-body">
                            <table id="table" class="table table-responsive table-hover">
                                <thead>
                                <tr>
                                    <th>序号</th>
                                    <th>姓名</th>
                                    <th>邮箱</th>
                                    <th>年龄</th>
                                    <th>电话</th>
                                    <th>角色</th>
                                    <th>状态</th>
                                    <th>创建时间</th>
                                    <th>地址</th>
                                    <th>部门名称</th>
                                    <th>公司名称</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <c:forEach items="${pageInfo.list}" var="vo">
                                    <tr>
                                        <td>${vo.userId}</td>
                                        <td>${vo.infoRealname}</td>
                                        <td>${vo.infoEmail}</td>
                                        <td>${vo.infoAge}</td>
                                        <td>${vo.infoPhonenum}</td>
                                        <td>
                                            <c:if test="${vo.roleId==1}">产废操作员</c:if>
                                            <c:if test="${vo.roleId==2}">库房操作员</c:if>
                                            <c:if test="${vo.roleId==3}">司机</c:if>
                                            <c:if test="${vo.roleId==4}">处理工厂</c:if>
                                            <c:if test="${vo.roleId==5}">运营商</c:if>
                                        </td>
                                        <td>
                                            <c:if test="${vo.userStatus==0}">启用</c:if>
                                            <c:if test="${vo.userStatus==1}">禁用</c:if>
                                        </td>
                                        <td><fmt:formatDate value="${vo.infoCreatetime}" pattern="yyyy-MM-dd"/></td>
                                        <td>${vo.infoAddress}</td>
                                        <td>
                                            <c:if test="${vo.deptId==1}">产废部</c:if>
                                            <c:if test="${vo.deptId==2}">库房部</c:if>
                                        </td>
                                        <td>${vo.companyName}</td>
                                        <td>
                                            <a class="btn btn-info" data-toggle="modal" data-target=".update"
                                               onclick="update(${vo.userId})">修改</a>
                                            <a class="btn btn-primary" data-toggle="modal" data-target=".power"
                                               onclick="power(${vo.roleId==null?"-1":vo.roleId},${vo.userId})">赋权</a>
                                            <a class="btn btn-danger"
                                               href="${pageContext.request.contextPath}/user/deleteById/${vo.userId}/${vo.infoId}">删除</a>
                                        </td>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                        </div>
                        <div style="margin-left: 20px">
                        共${pageInfo.total}条数据,当前第${pageInfo.pageNum}页,共${pageInfo.pages}页
                    </div>
                        <div class="footer">
                            <nav aria-label="Page navigation">
                                <ul class="pagination">
                                    <li>
                                        <a href="${pageContext.request.contextPath}/user/list/${pageInfo.prePage==0?1:pageInfo.prePage}"
                                           aria-label="Previous">
                                            <span aria-hidden="true">&laquo;</span>
                                        </a>
                                    </li>
                                    <c:forEach items="${pageInfo.navigatepageNums}" var="num">
                                        <li><a href="${pageContext.request.contextPath}/user/list/${num}">${num}</a>
                                        </li>
                                    </c:forEach>
                                    <li>
                                        <a href="${pageContext.request.contextPath}/user/list/${pageInfo.nextPage==0?pageInfo.pages:pageInfo.nextPage}"
                                           aria-label="Next">
                                            <span aria-hidden="true">&raquo;</span>
                                        </a>
                                    </li>
                                </ul>
                            </nav>
                        </div>
                    </div>
                </section>
            </div>
        </section>
    </div>
    <div class="modal fade power" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
        <div class="modal-dialog modal-sm" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">赋权</h4>
                </div>
                <form method="post" action="${pageContext.request.contextPath}/user/updateById">
                    <input type="hidden" name="userId" title="userId">
                    <div class="modal-body">
                        <select name="roleId">
                            <%--<option value="-1">请选择</option>--%>
                            <c:forEach items="${roleList}" var="role">
                                <option value="${role.roleId}">${role.roleName}</option>
                            </c:forEach>
                        </select>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary">提交</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <!-- Small modal -->
    <div class="modal fade update" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">修改用户信息</h4>
                </div>
                <form method="post" action="${pageContext.request.contextPath}/user/update">
                    <div class="modal-body">
                        <input type="hidden" name="userId">
                        <input type="hidden" name="infoId">
                        <input type="hidden" name="roleId">
                        <div class="form-group">
                            <label>LoginName</label>
                            <input type="text" class="form-control" placeholder="LoginName" name="userLoginname">
                        </div>
                        <div class="form-group">
                            <label>UserStatus</label>
                            <br/>
                            <input type="radio" placeholder="UserStatus" name="userStatus" title="off">禁用
                            <input type="radio" placeholder="UserStatus" name="userStatus" title="no">启用
                        </div>
                        <div class="form-group">
                            <label>RealName</label>
                            <input type="text" class="form-control" placeholder="RealName" name="infoRealname">
                        </div>
                        <div class="form-group">
                            <label>Phone</label>
                            <input type="text" class="form-control" placeholder="Phone" name="infoPhonenum">
                        </div>
                        <div class="form-group">
                            <label>Email</label>
                            <input type="text" class="form-control" placeholder="Email" name="infoEmail">
                        </div>
                        <div class="form-group">
                            <label>Age</label>
                            <input type="text" class="form-control" placeholder="Age" name="infoAge">
                        </div>
                        <div class="form-group">
                            <label>Address</label>
                            <input type="text" class="form-control" placeholder="Address" name="infoAddress">
                        </div>
                        <div class="form-group">
                            <label>DeptName</label>
                            <select name="deptId">
                                <c:forEach items="${deptList}" var="dept">
                                    <option value="${dept.deptId}">${dept.deptName}</option>
                                </c:forEach>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>CompanyName</label>
                            <select name="companyId">
                                <c:forEach items="${companyList}" var="company">
                                    <option value="${company.companyId}">${company.companyName}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary">提交</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {

    })

    /*给用户赋角色权限*/
    function power(roleId, userId) {
        $("[title='userId']").val(userId);
        console.log(roleId + "\t" + userId);
        $.ajax({
            type: "GET",
            url: "${pageContext.request.contextPath}/role/findById/" + roleId,
            dataType: "json",
            success: function (res) {
                console.log(res)
                if (res != null) {
                    $("[name='roleId']").val(res.roleId);
                }
            }
        })
    }

    /*回显数据*/
    function update(userId) {
        $.ajax({
            type: "GET",
            url: "${pageContext.request.contextPath}/user/findById/" + userId,
            dataType: "json",
            success: function (vo) {  //vo -->  UserVo对象
                console.log(vo);
                $("[name='userId']").val(vo.userId);
                $("[name='infoId']").val(vo.infoId);
                $("[name='userLoginname']").val(vo.userLoginname);
                if (vo.userStatus==0){
                    $("[title='no']").val(vo.userStatus).prop("checked", true);
                    $("[title='off']").val(1)
                }else{
                    $("[title='off']").val(vo.userStatus).prop("checked", true);
                    $("[title='no']").val(0)
                }
                $("[name='infoRealname']").val(vo.infoRealname);
                $("[name='infoPhonenum']").val(vo.infoPhonenum);
                $("[name='infoEmail']").val(vo.infoEmail);
                $("[name='infoAge']").val(vo.infoAge);
                $("[name='infoAddress']").val(vo.infoAddress);

                $("[name='deptId']").val(vo.deptId).prop("checked",true);
                $("[name='companyId']").val(vo.companyId).prop("checked",true);
            }
        })
    }




</script>
</body>

</html>
